<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of payment_model
 *
 * @author win7
 */
class payment_model extends admin_model {

    //put your code here
    public function __construct() {
        parent::__construct();
    }

    public function filter($nolimit = false) {
        $this->db->select('users.username ,payment.* ', false);
        $this->db->order_by('payment.id DESC');
        $this->db->join('users ', 'users.id=payment.user_id');
        $this->db->from('payment');

        $limit = metohd_get_uri('dblimit', ADMIN_LIMIT);


        $statrt_limit = get_segment(4, 0);
        if ($nolimit == false) {
            $this->db->limit($limit, $statrt_limit);
        }
        $sql = $this->db->get();

        return $sql->result();
    }

    public function save($data) {
        $data['create_date'] = date('Y-m-d H:i:s');
        $data['user_id'] = $this->admin_id;
        $this->db->insert('payment', $data);


        $data['id'] = $this->db->insert_id();
        $this->add_manager_report(array('action' => 'paymentr-add', 'contant' => $data));
        //return TRUE;
    }

    public function update($data, $id, $where = array()) {
        $data['update_date'] = date('Y-m-d H:i:s');
        $data['user_update'] = $this->admin_id;
        $where['id'] = $id;
        $this->db->update('payment', $data, $where);

        $data['id'] = $id;
        $this->add_manager_report(array('action' => 'paymentr-edit', 'contant' => $data));
        //return TRUE;
    }

    public function delete($id, $filename) {
        $this->db->delete('payment', array('id' => $id));
        $data['id'] = $id;
        $this->add_manager_report(array('action' => 'paymentr-delete', 'contant' => $data));
        @unlink(PAYMENT_PATH . $filename);
        return true;
    }

}

?>
